package com.djhu.freepartner.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.djhu.freepartner.bean.PartnerUser;
import com.djhu.freepartner.bean.UserStatus;
import com.djhu.freepartner.core.RestRsp;
import com.djhu.freepartner.core.Status;
import com.djhu.freepartner.dao.PartnerUserMapper;
import com.djhu.freepartner.service.IPartnerUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author zw
 * @since 2018-08-01
 */
@Service(value = "partnerUserService")
@Slf4j
public class PartnerUserServiceImpl extends ServiceImpl<PartnerUserMapper, PartnerUser> implements IPartnerUserService {

//    @Autowired
//    private PartnerUserMapper partnerUserMapper;

    @Override
    public int queryUserRegister(PartnerUser partnerUser) {
        return baseMapper.queryUserExisted(partnerUser);
    }

    @Override
    public RestRsp checkUser(String userid) {
        PartnerUser user = this.selectById(userid);
        RestRsp restRsp = new RestRsp();
        if (user == null) {
            log.info("用户不存在,userid is {}",userid);
            restRsp.setCode(Status.ACCOUNT_NOT_FOUND.getCode());
            restRsp.setMsg("用户不存在");
            return restRsp;
        }
        int code = Integer.parseInt(user.getStatus());
        if (code == UserStatus.FORBIDDEN.getCode()) {
            log.info("用户被禁言,userid is {}",userid);
            restRsp.setCode(Status.NO_PERMISSION.getCode());
            restRsp.setMsg("用户被禁言 ,无权发帖");
            return restRsp;
        }
        restRsp.setCode(Status.SUCCESS.getCode());
        return restRsp;
    }
}
